package com.ebei.platform.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * todo swagger 配置
 *
 * @author crazypenguin
 * @version 1.0
 * @created 2018/4/17
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Value("${bgy-server.SWAGGER_SWITCH}")
    private boolean swaggerShow;
    @Bean
    public Docket createRestApi() {
        ParameterBuilder tokenBuilder = new ParameterBuilder();
        List<Parameter> parameterList = new ArrayList<Parameter>();
//        tokenBuilder.name("Authorization")
//                .defaultValue("去其他请求中获取head中token参数")
//                .description("令牌")
//                .modelRef(new ModelRef("string"))
//                .parameterType("header")
//                .required(true).build();
//        parameterList.add(tokenBuilder.build());
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerShow)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(parameterList);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("BGY AccessControl Swagger API ")
                .description("BGY AccessControl API 文档")
                .termsOfServiceUrl("http://www.ebeitech.com")
                .version("1.0.0")
                .build();
    }

}